package com.lmx.repoDomain.tmodel;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiLookupIncludeAutomatically;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.lmx.repoDomain.tmodel.business.User;

/**
 * 楼宇表
 */
@JsonApiResource(type = "building")
@Table(name = "tnb_building")
@Entity
// @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Building extends BaseEntity {

	private String seq;// 编号

	private String remark;// 备注

	private String name;

	private User lastUpdateUser;// 更新操作者userid

	private Integer createDateTime;// 创建时间

	private User createUser;

	private Integer lastUpdateDateTime;// 更新时间

	private Integer upLandFloorNum;// 地上楼层数

	private Integer downLandFloorNum;// 地下楼层数

	// private List<Floor> floors;// 所包楼层

	private Integer roomNum;// 房间数
	private Integer bedAllNum;// 所有床位数
	private Integer bedInNum;// 在用数

	private Short create4Flag;// 是否生成4层

	private List<Floor> floors;

	@Transient
	@JsonApiToMany
	@JsonApiIncludeByDefault
	public List<Floor> getFloors() {
		return floors;
	}

	public void setFloors(List<Floor> floors) {
		this.floors = floors;
	}

	@Column(name = "bed_all_num")
	public Integer getBedAllNum() {
		return bedAllNum;
	}

	public void setBedAllNum(Integer bedAllNum) {
		this.bedAllNum = bedAllNum;
	}

	@Column(name = "bed_in_num")
	public Integer getBedInNum() {
		return bedInNum;
	}

	public void setBedInNum(Integer bedInNum) {
		this.bedInNum = bedInNum;
	}

	@Column(name = "room_num")
	public Integer getRoomNum() {
		return roomNum;
	}

	public void setRoomNum(Integer roomNum) {
		if (roomNum == null)
			roomNum = 0;
		this.roomNum = roomNum;
	}

	@Column(name = "create4_flag")
	public Short getCreate4Flag() {
		return create4Flag;
	}

	public void setCreate4Flag(Short create4Flag) {
		if (create4Flag == null)
			create4Flag = 0;
		this.create4Flag = create4Flag;
	}

	@Column(name = "upland_floornum")
	public Integer getUpLandFloorNum() {
		return upLandFloorNum;
	}

	public void setUpLandFloorNum(Integer upLandFloorNum) {
		this.upLandFloorNum = upLandFloorNum;
	}

	@Column(name = "downland_floornum")
	public Integer getDownLandFloorNum() {
		return downLandFloorNum;
	}

	public void setDownLandFloorNum(Integer downLandFloorNum) {
		this.downLandFloorNum = downLandFloorNum;
	}

	// @JsonApiToMany
	// @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy =
	// "building")
	// public List<Floor> getFloors() {
	// return floors;
	// }
	//
	// public void setFloors(List<Floor> floors) {
	// this.floors = floors;
	// }

	@Column(name = "createDateTime")
	public Integer getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(Integer createDateTime) {
		this.createDateTime = createDateTime;
	}

	@Column(name = "lastUpdateDateTime")
	public Integer getLastUpdateDateTime() {
		return lastUpdateDateTime;
	}

	public void setLastUpdateDateTime(Integer lastUpdateDateTime) {
		this.lastUpdateDateTime = lastUpdateDateTime;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "createuser_id", foreignKey = @ForeignKey(name = "null"))
	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	@JsonApiLookupIncludeAutomatically(overwrite = true)
	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "lastupdateuser_id", foreignKey = @ForeignKey(name = "null"))
	public User getLastUpdateUser() {
		return lastUpdateUser;
	}

	public void setLastUpdateUser(User lastUpdateUser) {
		this.lastUpdateUser = lastUpdateUser;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Building() {
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "seq")
	public String getSeq() {
		return seq;
	}

	public void setSeq(String seq) {
		this.seq = seq;
	}
}
